﻿namespace System.Web.Mvc
{
    public class AjaxController : Controller
    {
        public void RenderPartial(string viewName)
        {
            this.RenderPartial(viewName, ViewData);
        }

        public virtual void RenderPartial(string viewName, object viewData)
        {
            ViewContext viewContext = new ViewContext(ControllerContext,viewName,/* masterName */ null, viewData, TempData);
            ViewEngine.RenderView(viewContext);
        }
    }

    public static class UserControlExtensions
    {
        public static void RenderPartial(this Controller controller, string viewName, object viewData)
        {
            ViewContext viewContext = new ViewContext(controller.ControllerContext, viewName, /* masterName */ null, viewData, controller.TempData);
            controller.ViewEngine.RenderView(viewContext);
        }

        public static void RenderPartial(this Controller controller, string viewName)
        {
            RenderPartial(controller, viewName, controller.ViewData);
        }
    }
}
